package com.im.service;

import com.im.dao.DeptDao;
import com.im.pojo.Column;
import com.im.pojo.Dept;
import com.im.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.UUID;

@Service
public class DeptSrvImpl implements DeptService{
    @Autowired
    private DeptDao deptDao;
    @Override
    public int save(Dept dept) {
        Date date=new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//格式化时间
        String datetime=formatter.format(date);
        String uuid= UUID.randomUUID().toString().replace("-","");
        dept.setId(uuid);
        dept.setCreateTime(datetime);
        dept.setModifyTime(datetime);
        return deptDao.save(dept);
    }

    @Override
    public List delete(Dept dept) {
//        Date date=new Date();
//        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//格式化时间
//        String datetime=formatter.format(date);
//        dept.setModifyTime(datetime);
        List list1=null;
        List list=deptDao.deleteById(dept);
        if(list!=null&& list.size()>0){
            list1=list;
        }
        return list1;
    }

    @Override
    public int update(Dept dept) {
        Date date=new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//格式化时间
        String datetime=formatter.format(date);
        dept.setModifyTime(datetime);
        return deptDao.updateById(dept);
    }
    @Override
    public Dept query(Dept dept) {
        return deptDao.queryById(dept);
    }

    @Override
    public List queryAll(Dept dept) {
        if (dept.getName() != null && !"".equals(dept.getName())) {//java中判断是不是字符串!"".equals(column.getName())XML里判断是不是字符串and name!=''
            dept.setName("%"+dept.getName()+"%");
        }
        List list = deptDao.queryAll(dept);
        return list;
    }
}
